package edu.suda.xsap.service.impl;

import edu.suda.xsap.dto.MemberCardDto;
import edu.suda.xsap.dto.convert.MemberCardConvert;
import edu.suda.xsap.entity.MemberCard;
import edu.suda.xsap.mapper.MemberCardMapper;
import edu.suda.xsap.service.MemberCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class MemberCardServiceImpl implements MemberCardService {
    @Autowired
    private MemberCardMapper memberCardMapper;
    @Autowired
    private MemberCardConvert memberCardConvert;

    @Override
    public void delete(Integer id) {
        memberCardMapper.delete(id);
    }

    @Override
    public List<MemberCardDto> findAll() {
        return memberCardConvert.toDtoList(memberCardMapper.findAll());
    }

    @Override
    public MemberCardDto findById(Integer id) {
        return memberCardConvert.toDto(memberCardMapper.findById(id));
    }

    @Override
    public MemberCardDto findByName(String name) {
        return memberCardConvert.toDto(memberCardMapper.findByName(name));
    }

    @Override
    public void save(MemberCard memberCard) {
        memberCardMapper.save(memberCard);
    }

    @Override
    public void update(MemberCard memberCard) {
        memberCardMapper.update(memberCard);
    }

    //List<MemberCardDto> findByCardIds(List<Integer> cardIds);
    @Override
    public List<MemberCardDto> findByCardIds(List<Integer> cardIds) {
        return memberCardConvert.toDtoList(memberCardMapper.findByCardIds(cardIds));
    }

    @Override
    public List<Map<String, Object>> getCardTypeStatistics() {
        return memberCardMapper.findCardTypeStatistics();
    }
}
